/*
 * Copyright 2002-2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.deservel.wxopen.controller;

import com.deservel.wxopen.service.CoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 核心控制器类
 *
 * @author DeserveL
 * @date 2017/7/3 17:05
 * @since 1.0.0
 */
@RestController
@RequestMapping("")
public class CoreController {

    @Autowired
    CoreService coreService;

    /**
     * 验证是否来自微信服务器的消息
     *
     * @param signature
     * @param nonce
     * @param timestamp
     * @param echostr
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.GET)
    public String checkSignature(String signature, String nonce, String timestamp, String echostr) {
        return coreService.checkSignature(signature, nonce, timestamp, echostr);
    }

    /**
     * 接收消息、处理消息跟推送消息
     *
     * @param requestXml
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.POST)
    public String postMessage(@RequestBody String requestXml) {
        return coreService.postMessage(requestXml);
    }
}
